Repository navigation
samples: a token template and a Python client that calls contracts with the declared types - #135
Merged
Merged
Conversation
…th the declared types samples/contracts/Token.java is a token to start from: SmartContract v3 and ExtensionTokenStandard v1 (token standard 4). Every amount is checked (positive, at most the token's decimals), balances and allowances are kept at the token's scale, approve() sets the allowance as ERC-20 does instead of adding to it, payable() sells tokens for CS at a price. The executor harness runs it on every executor (template_token). samples/python/token_client.py lists a contract's methods (SmartContractGet, then ContractAllMethodsGet), reads a getter through TransactionFlow with forgetNewState (free, nothing sent) and signs and sends a call; each argument is converted to the type the method declares (String, BigDecimal, int, long, boolean, double and wrappers, byte[]), which the executor requires.
…aces them for the token API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
samples/contracts/Token.java: a token template to start from, SmartContract v3 + ExtensionTokenStandard v1 (token standard 4, recognised by wallets and the token API). Compared with the templates around: every amount is checked (positive, no more decimals than the token has: no dust), balances and allowances are kept at the token's scale (5 and 5.000 are one value),approve()sets the allowance as ERC-20 does instead of adding to it,payable()sells tokens for CS at a price, owner-only freeze. The executor harness runs it on every executor (template_token), so the executor CI covers it.samples/python/token_client.py: lists a contract's methods (SmartContractGet+ContractAllMethodsGet), reads a getter for free (TransactionFlowwithforgetNewState) and signs and sends a call, converting every argument to the type the method declares (String, BigDecimal, int, long, boolean, double and wrappers, byte[]): the executor finds no method otherwise (api: refuse a contract call whose method the executor cannot find #132 refuses such calls before they are sent).docs/tokens.md: a section on both.Samples and CI only.
Test plan
methods,get balanceOf,get getName, a signedcall transfer <wallet> 1.5(returned True, the balance read afterwards is 1.500), a wrong argument count reported with the method's signature🤖 Generated with Claude Code